package cz.anime.ppro.logic;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cz.anime.ppro.model.Message;
import cz.anime.ppro.repositories.MessageRepository;

@Component
public class MessageComponentImpl implements MessageComponent {

	@Autowired
	private MessageRepository messageRepository;
	
	@Override
	public List<Message> getMessages() {
		return messageRepository.findAll();
	}
	
	@Override
	public List<Message> getInMessages(int id) {
		return messageRepository.findMessageByWebuser2Id(id);
	}
	
	@Override
	public List<Message> getOutMessages(int id) {
		return messageRepository.findMessageByWebuser1Id(id);
	}
	
	@Override
	public void saveMessage(Message message) {
		messageRepository.saveAndFlush(message);
	}

}
